home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 December / maximum-cd-2009-12.iso / DiscContents / gimp-2.7.0-i686-setup.exe / {app} / lib / gimp / 2.0 / plug-ins / foggify.py < prev    next >
Encoding:
Python Source  |  2009-08-19  |  2.4 KB  |  78 lines

  1. #!/usr/bin/env python
  2.  
  3. #   Gimp-Python - allows the writing of Gimp plugins in Python.
  4. #   Copyright (C) 1997  James Henstridge <james@daa.com.au>
  5. #
  6. #   This program is free software: you can redistribute it and/or modify
  7. #   it under the terms of the GNU General Public License as published by
  8. #   the Free Software Foundation; either version 3 of the License, or
  9. #   (at your option) any later version.
  10. #
  11. #   This program is distributed in the hope that it will be useful,
  12. #   but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #   GNU General Public License for more details.
  15. #
  16. #   You should have received a copy of the GNU General Public License
  17. #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  
  19. from gimpfu import *
  20. import time
  21.  
  22. gettext.install("gimp20-python", gimp.locale_directory, unicode=True)
  23.  
  24. def foggify(img, layer, name, colour, turbulence, opacity):
  25.  
  26.     gimp.context_push()
  27.     img.undo_group_start()
  28.  
  29.     if img.base_type is RGB:
  30.         type = RGBA_IMAGE
  31.     else:
  32.         type = GRAYA_IMAGE
  33.     fog = gimp.Layer(img, name,
  34.                      layer.width, layer.height, type, opacity, NORMAL_MODE)
  35.     fog.fill(TRANSPARENT_FILL)
  36.     img.add_layer(fog, 0)
  37.  
  38.     gimp.set_background(colour)
  39.     pdb.gimp_edit_fill(fog, BACKGROUND_FILL)
  40.  
  41.     # create a layer mask for the new layer
  42.     mask = fog.create_mask(0)
  43.     fog.add_mask(mask)
  44.  
  45.     # add some clouds to the layer
  46.     pdb.plug_in_plasma(img, mask, int(time.time()), turbulence)
  47.  
  48.     # apply the clouds to the layer
  49.     fog.remove_mask(MASK_APPLY)
  50.  
  51.     img.undo_group_end()
  52.     gimp.context_pop()
  53.  
  54. register(
  55.     "python-fu-foggify",
  56.     N_("Add a layer of fog"),
  57.     "Adds a layer of fog to the image.",
  58.     "James Henstridge",
  59.     "James Henstridge",
  60.     "1999,2007",
  61.     N_("_Fog..."),
  62.     "RGB*, GRAY*",
  63.     [
  64.         (PF_IMAGE, "image",       "Input image", None),
  65.         (PF_DRAWABLE, "drawable", "Input drawable", None),
  66.         (PF_STRING, "name",       _("_Layer name"), _("Clouds")),
  67.         (PF_COLOUR, "colour",     _("_Fog color"),  (240, 180, 70)),
  68.         (PF_SLIDER, "turbulence", _("_Turbulence"), 1.0, (0, 10, 0.1)),
  69.         (PF_SLIDER, "opacity",    _("Op_acity"),    100, (0, 100, 1)),
  70.     ],
  71.     [],
  72.     foggify,
  73.     menu="<Image>/Filters/Render/Clouds",
  74.     domain=("gimp20-python", gimp.locale_directory)
  75.     )
  76.  
  77. main()
  78.